package cn.ecut.servlet;

import cn.ecut.model.Comment;
import cn.ecut.services.Commentservices;
import cn.ecut.util.StatusCode;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CommentListServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String pagenum=req.getParameter("pagenum");
        Integer begin=Integer.valueOf(pagenum);
        String newsid=req.getParameter("newsid");
        Commentservices commentservices=new Commentservices();
        List<Comment> comments=commentservices.CommentList(begin,newsid);
        Map<String,Object> map=new HashMap<>();
        if(comments.size()>0){
            map.put("data",comments);
            map.put("status", StatusCode.SUCCESS);
            map.put("msg","成功");
        }else{
            map.put("status", StatusCode.SERVER_ERROR);
            map.put("msg","失败");
        }
        resp.getWriter().write(JSON.toJSONString(map));
    }
}
